#include <stdio.h>


/*
 *	swap
 */




void swap_w( int a, int b )
{  
    int temp; 
	
    temp = a;  
    a = b;  
    b = temp;   
} 

void swap_p( int *a, int *b )
{  
    int *temp; 
	
    temp = NULL;  
    temp = a;  
    a = b;  
    b = temp;   
}  

void swap_px( int *a, int *b )
{  
    int *temp; 
	
	// 此函数改变了a,b的值，只不过由于是指针的关系，当值被修改后，变量被一起修改了。
	printf("swap_px1 %d %d\n", *a, *b);	// 16 32
    *temp = *a;  
	printf("swap_px2 %d %d %d\n", *a, *b, *temp);	// 16 32 16
    *a = *b;  
	printf("swap_px3 %d %d %d\n", *a, *b, *temp);	// 32 32 32
    *b = *temp;   
	printf("swap_px4 %d %d %d\n", *a, *b, *temp);	// 32 32 32
}  

void swap_pp( int **a, int **b )
{
    int *tmp = NULL; 
	
    tmp = *a;  
    *a = *b;  
    *b = tmp;  
}

void test_swap_pp()
{
	int a,b;  
	int *pa, *pb;

    a = 16;  
    b = 32;  

	pa = &a;
	pb = &b;

	swap_pp(&pa, &pb); 	
	printf("%d\n", *pa - *pb);	// 16
	printf("%d\n", a - b);		// -16
}

int main ( int argc, char **argv )
{  
    int a,b;  

    a = 16;  
    b = 32;  

	swap_w(a, b); 	
	printf("%d\n", a - b);	// -16

	a = 16;  
    b = 32; 
    swap_p(&a, &b); 	
	printf("%d\n", a - b);	// -16

	a = 16;  
    b = 32; 
	swap_px(&a, &b); 	
	printf("%d\n", a - b);	// 0. 此函数改变了a,b的值，只不过由于是指针的关系，当值被修改后，变量被一起修改了。

	test_swap_pp();
	

    return 0;  
}





